﻿@using SmartStore.Core.Domain.Stores;
@using SmartStore.Services.Customers;
@using SmartStore.Services.Stores;
@using SmartStore.Core;

@{
	var currentCustomer = this.WorkContext.CurrentCustomer;
	var currentLanguage = this.WorkContext.WorkingLanguage;
	var userName = (string)ViewBag.UserName;
	var stores = ((IList<Store>)ViewBag.Stores) ?? new List<Store>();
	string currentLanguageCode = currentLanguage.UniqueSeoCode.EmptyNull().ToLower();
	string communityUrl = (currentLanguageCode == "de" ?
		"http://community.smartstore.com" :
		"http://community.smartstore.com/index.php?/&k=880ea6a14ea49e853634fbdc5015a024&setlanguage=1&cal_id=&langid=1");
	string docsUrl = GenerateHelpUrl("");
	var checkUpdateResult = ViewBag.CheckUpdateResult as CheckUpdateResult;
}

<nav id="navbar" class="navbar navbar-dark navbar-expand">
    
    <a class="navbar-brand mx-0 mr-3" href="@Url.Action("Index", "Home", new { area = "Admin" })">
        @*<img src="~/Administration/Content/images/smnet2.png" alt="smartstore.NET" />*@
		<img class="navbar-img d-none d-lg-block" src="~/Administration/Content/images/smartstore.svg" alt="smartstore.NET" />
		<img class="navbar-img d-lg-none" src="~/Administration/Content/images/smartstore-icon.svg" alt="smartstore.NET" />
	</a>

	<div id="navbar-menu" class="collapse navbar-collapse mr-auto">
		@{
			Html.RenderWidget("admin_menu_before");
            Html.SmartStore().Menu().Name("Admin").Render();
            Html.RenderWidget("admin_menu_before");
		}
	</div>
    
	<div class="collapse navbar-collapse ml-auto">
		<ul class="navbar-nav ml-auto">

			<li class="nav-item dropdown">
				<a class="nav-link dropdown-toggle navbar-tool" href="javascript:void(0)" title='@T("Admin.Common.Actions")' data-toggle="dropdown">
					<i class="icm icm-cog navbar-icon"></i>
				</a>
				<div class="dropdown-menu dropdown-menu-right">
					@foreach (var store in stores)
					{
						<a class="dropdown-item" href="@store.Url" title="@T("Admin.Header.PublicStore") - @store.Name">
							<i class="fa fa-fw fa-globe"></i>
							@store.Name.Truncate(32, "...")
						</a>
					}
					<a class="dropdown-item" href='@Url.Action("Preview", "Theme")'>
						<i class="far fa-fw fa-eye"></i>
						@T("Admin.Configuration.Themes.PreviewMode")
					</a>
					<div class="dropdown-divider"></div>
					<a class="dropdown-item" href="@Url.Action("ClearCache", "Common", new { previousUrl = Request.RawUrl, area = "Admin" })">
						<i class="far fa-fw fa-trash-alt"></i>
						@T("Admin.Header.ClearCache")
					</a>
					<a class="dropdown-item" href="@Url.Action("ClearDatabaseCache", "Common", new { previousUrl = Request.RawUrl, area = "Admin" })">
						<i class="fa fa-fw"></i>
						@T("Admin.Header.ClearDbCache")
					</a>
					<div class="dropdown-divider"></div>
					<a class="dropdown-item" id="restart-application" href="#" data-url="@Url.Action("RestartApplication", "Common", new { previousUrl = Request.RawUrl, area = "Admin" })">
						<i class="fa fa-fw fa-power-off"></i>
						@T("Admin.Header.RestartApplication")
					</a>
				</div>
			</li>

			@{ Html.RenderAction("LanguageSelector", "Common", new { area = "Admin" }); }

			<li id="navtool-help" class="nav-item dropdown d-none d-md-block">
				<a class="nav-link dropdown-toggle navbar-tool" href="javascript:void(0)" title='@T("Admin.Help")' data-toggle="dropdown">
					<i class="icm icm-bubble-question navbar-icon"></i>
					@if (checkUpdateResult != null && checkUpdateResult.UpdateAvailable)
					{
						<span class="reddot" style="top: 25px; right: 7px"></span>
					}
				</a>
				<div class="dropdown-menu dropdown-menu-right">
					@if (checkUpdateResult != null && checkUpdateResult.UpdateAvailable)
					{
						<a class="dropdown-item" href='@Url.Action("CheckUpdate", new { area = "Admin" })'>
							<i class="fa fa-fw fa-level-up-alt"></i>
							<strong>@T("Admin.CheckUpdate.UpdateAvailable")</strong>
							<span class="reddot" style="margin-left: 6px"></span>
						</a>
					}
					<a class="dropdown-item" href="@docsUrl" data-lang="@currentLanguageCode" target="help">
						<i class="fa fa-fw fa-book"></i>
						@T("Admin.Help.Documentation")
					</a>
					<a class="dropdown-item" href="@communityUrl" data-lang="@currentLanguageCode" target="help">
						<i class="fa fa-fw fa-comment"></i>
						@T("Admin.Help.Forums")
					</a>
					<div class="dropdown-divider"></div>
					<a class="dropdown-item" href="@Url.Action("About", "Home", new { area = "Admin" })">
						<i class="fa fa-fw fa-info-circle"></i>
						@T("Admin.Common.About")
					</a>
				</div>
			</li>

			@if (currentCustomer != null && currentCustomer.IsRegistered())
			{
				<li class="nav-item dropdown ml-md-3">
					<a id="current-user" class="nav-link dropdown-toggle navbar-tool" data-toggle="dropdown" title="@userName" href='@Url.Action("Edit", "Customer", new { id = currentCustomer.Id, area = "Admin" })'>
						@*<em class="fa-stack fa-lg">
							<i class="fa fa-circle fa-stack-2x"></i>
							<i class="icm icm-user navbar-icon" style="color: #3b50ce"></i>
						</em>*@
						<i class="icm icm-user navbar-icon"></i>
					</a>
					<div class="dropdown-menu dropdown-menu-right">
						<a class="dropdown-item" href="@Url.Action("Edit", "Customer", new { id = currentCustomer.Id, area = "Admin" })">
							<i class="fa fa-fw fa-user"></i>
							@T("Admin.Header.Account")
						</a>
						<a class="dropdown-item" href="@Url.Action("Logout", "Customer", new { area = "" })">
							<i class="fal fa-fw fa-sign-out-alt"></i>
							@T("Admin.Header.Logout")
						</a>
					</div>
				</li>
			}

		</ul>
	</div>

</nav>


<script type="text/javascript">

    $(function () {

        $("#restart-application").on('click', function (e) {
            e.preventDefault();
            $.throbber.show({
                message: @T("Admin.Header.RestartApplication.Progress").JsText,
                callback: function () {
                    setLocation($(e.target).data("url"));
                    
                }
            });
            return false;
        });

        // add mainmenu tooltips;
        $('#tools [rel=tooltip]').tooltip({ 
            placement: 'bottom'
        });

    });
          
</script>

